//
//  CLReadParser.h
//  CLBrowser
//
//  Created by 梁慧聪 on 2022/7/10.
//

#import <Foundation/Foundation.h>
@class CLBook,CLReadChapterModel,CLReadPageModel,CLReadModel;
NS_ASSUME_NONNULL_BEGIN

/// 解析完成
typedef void(^CLParserCompletion)(CLReadModel *readModel);

@interface CLReadParser : NSObject
@property (nonatomic, strong) NSMutableArray <CLBook *>*books;
SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(CLReadParser);
- (void)readCache;
- (CLBook *)bookById:(NSString *)bookid;
- (NSArray<CLBook *>*)booksWithWhere:(NSString *)where;
- (NSArray<CLReadChapterModel *>*)chaptersWithWhere:(NSString *)where;
- (CLReadChapterModel *)chapterById:(NSString *)chapterid;
- (CLBook *)saveToDBWithBookInfo:(NSDictionary *)bookInfo;
- (CLReadChapterModel *)saveToDBWithChapterInfo:(NSDictionary *)chapterInfo;
/// 内容分页
///
/// - Parameters:
///   - attrString: 内容
///   - rect: 显示范围
///   - isFirstChapter: 是否为本文章第一个展示章节,如果是则加入书籍首页。(小技巧:如果不需要书籍首页,可不用传,默认就是不带书籍首页)
/// - Returns: 内容分页列表
+ (NSArray <CLReadPageModel *>*)pageingWithAttrString:(NSAttributedString *)attrString rect:(CGRect)rect isFirstChapter:(BOOL)isFirstChapter;
// MARK: -- 解码URL

/// 解码URL
///
/// - Parameter url: 文件路径
/// - Returns: 内容
+ (NSString *)encode:(NSURL *)url;
/// 解析URL
///
/// - Parameters:
///   - url: 文件路径
///   - encoding: 进制编码
/// - Returns: 内容
+ (NSString *)encode:(NSURL *)url encoding:(NSStringEncoding)encoding;

+ (NSString *)contentTypesetting:(NSString *)content;
@end

NS_ASSUME_NONNULL_END
